package com.memorypalace.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class AJaxUtil {
	public static void sendJsonByObj(Object obj,HttpServletResponse response) {
		Gson gson = new Gson();
		String obj_json = gson.toJson(obj);
		System.out.println("obj_json:"+obj_json);
		response.setCharacterEncoding("utf-8");
		try {
			PrintWriter out = response.getWriter();
			out.write(obj_json);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void sendJsonByString(String str,HttpServletResponse response) {
		response.setCharacterEncoding("utf-8");
		try {
			PrintWriter out = response.getWriter();
			out.write(str);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
